Skip to content

[rtl] Switch to ratified bitmanip extensions#2459

Open
thommythomaso wants to merge 20 commits into
lowRISC:masterfrom
thommythomaso:tbenz/bitmanip
Open

[rtl] Switch to ratified bitmanip extensions#2459
thommythomaso wants to merge 20 commits into
lowRISC:masterfrom
thommythomaso:tbenz/bitmanip

Conversation

@thommythomaso

Copy link
Copy Markdown
Contributor

No description provided.

@thommythomaso thommythomaso self-assigned this Jul 13, 2026
@thommythomaso
thommythomaso force-pushed the tbenz/bitmanip branch 2 times, most recently from d0b04a1 to 359815f Compare July 14, 2026 15:23
Signed-off-by: Thomas Benz <tbenz@lowrisc.org>
Signed-off-by: Thomas Benz <tbenz@lowrisc.org>
Signed-off-by: Thomas Benz <tbenz@lowrisc.org>
Signed-off-by: Thomas Benz <tbenz@lowrisc.org>
Signed-off-by: Thomas Benz <tbenz@lowrisc.org>
Signed-off-by: Thomas Benz <tbenz@lowrisc.org>
Signed-off-by: Thomas Benz <tbenz@lowrisc.org>
Signed-off-by: Thomas Benz <tbenz@lowrisc.org>
Signed-off-by: Thomas Benz <tbenz@lowrisc.org>
Signed-off-by: Thomas Benz <tbenz@lowrisc.org>
Signed-off-by: Thomas Benz <tbenz@lowrisc.org>
Signed-off-by: Thomas Benz <tbenz@lowrisc.org>
Signed-off-by: Thomas Benz <tbenz@lowrisc.org>
Signed-off-by: Thomas Benz <tbenz@lowrisc.org>
Signed-off-by: Thomas Benz <tbenz@lowrisc.org>
Signed-off-by: Thomas Benz <tbenz@lowrisc.org>
Signed-off-by: Thomas Benz <tbenz@lowrisc.org>
Signed-off-by: Thomas Benz <tbenz@lowrisc.org>
Signed-off-by: Thomas Benz <tbenz@lowrisc.org>
Signed-off-by: Thomas Benz <tbenz@lowrisc.org>

@marnovandermaas marnovandermaas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial comments from me. Do you think it is worth squashing the commits that just remove things? I think it may be excessive to have 9 separate commits for removing instructions.

Comment thread rtl/ibex_decoder.sv
Comment on lines -468 to -469
{7'b000_0100, 3'b100}, // pack
{7'b000_0100, 3'b111}, // packh

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The zexth commit also remove pack and packh

Comment thread rtl/ibex_decoder.sv
5'b0_0000: alu_operator_o = ALU_SRL; // Shift Right Logical by Immediate
5'b0_1000: alu_operator_o = ALU_SRA; // Shift Right Arithmetically by Immediate
5'b0_1001: alu_operator_o = ALU_BEXT; // Extract bit specified by immediate.
// rori (Zbb, also imported by Zbkb): rotate right by immediate

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does changing this comment complete Zbkb?

Comment on lines -11 to +12
* `RISC-V Bit-Manipulation Extension, version 1.0.0 <https://github.com/riscv/riscv-bitmanip/releases/download/1.0.0/bitmanip-1.0.0-38-g865e7a7.pdf>`_ and `version 0.93 (draft from January 10, 2021) <https://github.com/riscv/riscv-bitmanip/blob/master/bitmanip-0.93.pdf>`_
* `RISC-V Bit-Manipulation Extension, version 1.0.0 <https://github.com/riscv/riscv-bitmanip/releases/download/1.0.0/bitmanip-1.0.0-38-g865e7a7.pdf>`_
* `RISC-V Scalar Cryptography Extension, version 1.0.1 <https://github.com/riscv/riscv-crypto/releases/download/v1.0.1-scalar/riscv-crypto-spec-scalar-v1.0.1.pdf>`_ (Zbkb, Zbkx sub-extensions only)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit for this shouldn't be marked as RTL. Probably [doc,dv] would be better.

@thommythomaso

Copy link
Copy Markdown
Contributor Author

Initial comments from me. Do you think it is worth squashing the commits that just remove things? I think it may be excessive to have 9 separate commits for removing instructions.

I have them as individual commits to help people review the changes. I would have squashed all into one after the review process. What do you think?

@thommythomaso
thommythomaso marked this pull request as ready for review July 16, 2026 06:53

@SamuelRiedel SamuelRiedel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for cleaning up the bitmanip @thommythomaso. I did a quite thorough review, but most of it should be easy to fix.

The only thing that is left is that we should update RISC-V DV to also support the latest ratified extensions. I saw that the ratified B extensions are supported already, but for the scalar crypto ones, we currently simply enable the Zbp still, right? I think this is good enough for now, but we should create an issue documenting the current state, like which instructions are emitted by riscv-dv and which aren't and what we would ideally want to then clean up the DV in a second step at least.

Ibex implements the Machine ISA version 1.12.
* `RISC-V External Debug Support, version 0.13.2 <https://content.riscv.org/wp-content/uploads/2019/03/riscv-debug-release.pdf>`_
* `RISC-V Bit-Manipulation Extension, version 1.0.0 <https://github.com/riscv/riscv-bitmanip/releases/download/1.0.0/bitmanip-1.0.0-38-g865e7a7.pdf>`_ and `version 0.93 (draft from January 10, 2021) <https://github.com/riscv/riscv-bitmanip/blob/master/bitmanip-0.93.pdf>`_
* `RISC-V Bit-Manipulation Extension, version 1.0.0 <https://github.com/riscv/riscv-bitmanip/releases/download/1.0.0/bitmanip-1.0.0-38-g865e7a7.pdf>`_

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we explicitly mention the subextensions? The "B" only stands for Zba, Zbb, and Zbs in the ISA string, but then the Zbc is also part of the bit manipulation extension. This is a bit confusing in the RISC-V spec already, but I would explicitly mention what we support already in this file here and in the list below.


* - **B**: Standard Extension for Bit-Manipulation Instructions
- 1.0.0 + 0.93 [#B_draft]_
- 1.0.0 [#B_draft]_

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This footnote doesn't really make sense anymore. We have the same footnote, named B_draft internally that describes what the fully ratified B extension entails and then also refer to the same footnote for the scalar crypto one. Let's have one footnote each or just leave them away, since the scalar crypto is already clear on its own and if we clarify the bitmanip above already, I also don't think we need a footnote specifying the subextensions anymore.


Bit-Manipulation Extension
Support for the `RISC-V Bit-Manipulation Extension version 1.0.0 <https://github.com/riscv/riscv-bitmanip/releases/download/1.0.0/bitmanip-1.0.0-38-g865e7a7.pdf>`_ and `draft version 0.93 from January 10, 2021 <https://github.com/riscv/riscv-bitmanip/blob/master/bitmanip-0.93.pdf>`_ is optional. [#B_draft]_
Support for the `RISC-V Bit-Manipulation Extension version 1.0.0 <https://github.com/riscv/riscv-bitmanip/releases/download/1.0.0/bitmanip-1.0.0-38-g865e7a7.pdf>`_, together with the Zbkb and Zbkx sub-extensions of the ratified Scalar Cryptography Extension, is optional. [#B_draft]_

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, outdated footnote name

Comment on lines -104 to -105
The implementation of the Bit-Manipulation Extension comes with an area overhead of 2.7 kGE for the balanced version, 6.1 kGE for the OTEarlGrey version, and 7.5 kGE for the full version.
These numbers were obtained by synthesizing the design with Yosys and relaxed timing constraints.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any new numbers for those? Even if we could simply estimate them?

Comment thread dv/cosim/spike_cosim.cc
Comment on lines +577 to +583
uint32_t misa_val = processor->get_csr(CSR_MISA);
if (rv32b_enabled) {
misa_val |= 1 << 1;
}
processor->get_state()->csrmap[CSR_MISA] =
std::make_shared<const_csr_t>(processor.get(), CSR_MISA, misa_val);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the B extension a special case here where we need to parse the ISA string ourselves and inject it into the MISA register? Shouldn't this be handled the same way as all the other extensions?

Comment thread rtl/ibex_decoder.sv
end
5'b0_1001, // bclri
5'b0_0101, // bseti
5'b0_1101: illegal_insn = (RV32B != RV32BNone) ? 1'b0 : 1'b1; // binvi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These instructions require instr[25] to be zero as well in RV32, which is never checked, right?

Comment thread rtl/ibex_decoder.sv
Comment on lines 417 to +418
if ({instr[26], instr[13:12]} == {1'b1, 2'b01}) begin
illegal_insn = (RV32B != RV32BNone) ? 1'b0 : 1'b1; // cmix / cmov / fsl / fsr
illegal_insn = 1'b1; // cmix / cmov / fsl / fsr removed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this? They will simply fall under the default case later, right? I think the comment will be a bit confusing if someone looks at this without the context of the bitmanip just being cleaned up.

Comment thread rtl/ibex_decoder.sv
default: ;
endcase
end
// Ternary bitmanip ops (cmix/cmov/fsl/fsr) removed; these encodings are illegal.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we again have an empty if block and the else only contains a switch case with legal encodings, so we could directly use the switch case only, no?

Comment thread rtl/ibex_tracer_pkg.sv
@@ -124,174 +116,30 @@ package ibex_tracer_pkg;
parameter logic [31:0] INSN_BEXT = { 7'b0100100, 10'h?, 3'b101, 5'h?, {OPCODE_OP} };

// ZBP

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention of old extension

Comment thread rtl/ibex_alu.sv
// The generalized-reverse / or-combine butterfly below implements the ratified
// subset only: rev8 and orc.b.

logic [4:0] zbp_shift_amt;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention of old extension in variable name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants